package cgo

type IGoManagedPtr interface {
	~uintptr
	Delete()
}

type GoManagedPtr[T IGoManagedPtr] uintptr

//go:force inline
func (g GoManagedPtr[T]) Get() T {
	return T(uintptr(g))
}

//go:force inline
func (g GoManagedPtr[T]) Release() {
	v := g.Get()
	v.Delete()
}

//go:force inline
func MakePtr[T ~uintptr](ptr uintptr) T {
	return T(ptr)
}

type NotUsed struct{}

//go:force inline
func ToManaged[T IGoManagedPtr](t T) GoManagedPtr[T] {
	return GoManagedPtr[T](t)
}
